<?php
include_once($_SERVER['DOCUMENT_ROOT']."/collect/reset/t.class.php");
include_once($_SERVER['DOCUMENT_ROOT']."/collect/common/yzs1013_pldr.php");

$t=new t("127.0.0.1","root","159456","longzs");
$host=host($_GET[url]);
$data=array();

if($_GET[type]=="get"){
  $sql="SELECT ip FROM proxy p LEFT JOIN proxy_host h ON p.ip=h.proxy AND h.host='{$host}' LEFT JOIN proxy_url u ON p.ip=u.proxy WHERE p.is_delete=0 AND h.id IS NULL  AND (u.jumpurl<>'' OR u.jumpurl IS NULL) AND p.ip NOT IN(SELECT proxy FROM proxy_url WHERE jumpurl='{$_GET[url]}') ORDER BY p.dateline limit 0,1";
  $aproxy=$t->sqlvalue($sql);//order by p.dateline  or rand()
  echo $aproxy;
}

if($_GET[type]=="del"){
  $t->execute("update proxy set dateline='".date("Y-m-d H:i:s")."',is_delete=1 where ip='$_GET[proxy]'");
}

if($_GET[type]=="timeout"){
  $data[dateline]=date("Y-m-d H:i:s");
  $data[host]=$host;
  $data[is_timeout]=1;
  $data[proxy]=$_GET[proxy];
  if($_GET[proxy]!=""&&$host!=""){
    $t->rk("proxy_host", "dateline,is_timeout,host,proxy", "host='$host' and proxy='$_GET[proxy]'",array("insert"=>1), $data);
  }
}

if($_GET[type]=="jumpurl"){
  $data[dateline]=date("Y-m-d H:i:s");
  $data[jumpurl]=$_GET[url];
  $data[proxy]=trim($_GET[proxy]);
  if($_GET[proxy]!=""&&$_GET[url]!="") {
    $t->rk("proxy_url", "dateline,jumpurl,proxy", "jumpurl='$_GET[url]' and proxy='$_GET[proxy]'", array("insert" => 1), $data);
  }
}
?>